--
-- Find names of things using a command
--

local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)

-- Adapted from : https://forum.minetest.net/viewtopic.php?p=186338&sid=9a7e8dcda0622c5c390ba43bbaf308fc#p186338
minetest.register_chatcommand("find", {
	params = "<keyword>",
	description = S("find item names or list all items"),
	privs = {},
	func = function(name, param)
		--minetest.chat_send_player(name, "")
		local parami=""
		if param~=nil then
			parami=param
		end
		minetest.chat_send_player(name,
        minetest.colorize("#2b74ff","------------------------nodes"))
        
		for n, i in pairs(minetest.registered_nodes) do
			if string.find(n, parami) then
				minetest.chat_send_player(name, n)
			end
		end
		minetest.chat_send_player(name,
        minetest.colorize("#2b74ff","------------------------tools"))
        
		for n, i in pairs(minetest.registered_tools) do
			if string.find(n, parami) then
				minetest.chat_send_player(name, n)
			end
		end
		minetest.chat_send_player(name,
        minetest.colorize("#2b74ff","------------------------craftitems"))

		for n, i in pairs(minetest.registered_craftitems) do
			if string.find(n, parami) then --plain text search
				minetest.chat_send_player(name, n)
			end
		end
		minetest.chat_send_player(name,
        minetest.colorize("#2b74ff","------------------------aliases"))

		for n, i in pairs(minetest.registered_aliases) do
			if string.find(n, parami) then --plain text search
				minetest.chat_send_player(name, n)
			end
		end

	end,

})
